package andev.lopengles;

import android.app.ActivityManager;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.opengl.GLSurfaceView;
import android.os.Bundle;

import andev.aandroidlib.activity.AActivity;
import andev.lopengles.Renderer.Renderer1;

public class MainActivity extends AActivity {
    private GLSurfaceView mGLSurfaceView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        mGLSurfaceView = new GLSurfaceView(this);

        //Check if the system supports opengl es 2
        final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        final ConfigurationInfo configurationInfo = activityManager.getDeviceConfigurationInfo();
        final boolean bSupportES2 = configurationInfo.reqGlEsVersion >= 0x20000;

        if (bSupportES2) {
            //Request an OpenGL ES 2 compatible context
            mGLSurfaceView.setEGLContextClientVersion(2);

            //Set up our renderer
            mGLSurfaceView.setRenderer(new Renderer1());
        }
        setContentView(mGLSurfaceView);
    }

    /*
     * The activity must call the GL surface view's onResume() on activity onResume().
     */
    @Override
    protected void onResume() {
        super.onResume();
        mGLSurfaceView.onResume();
    }

    /*
     * The activity must call the GL surface view's onPause() on activity onPause().
     */
    @Override
    protected void onPause() {
        super.onPause();
        mGLSurfaceView.onPause();
    }
}
